/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\121.买卖股票的最佳时机.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-04-13 20:15:56
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-13 20:34:34
 */
/*
 * @lc app=leetcode.cn id=121 lang=cpp
 *
 * [121] 买卖股票的最佳时机
 */

// @lc code=start
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        if(prices.size() <= 1)
            return 0;

        int _min = prices[0];
        int _max = 0;
        for(int i = 1 ; i < prices.size() ; i++)
        {
            _max = max(_max,prices[i] - _min);
            _min = min(_min,prices[i]);
        }
        return _max;
    }
};
// @lc code=end

